package com.startrek.ch02;

public class TwoDimensionalArray {

    public boolean find(int[][] a, int key) {
        int rows = a.length;
        int cols = a[0].length;
        int row = 0, col = cols - 1;

        while (row < rows && col >= 0) {
            int target = a[row][col];
            if (target == key)
                return true;
            else if (target > key)
                col--;
            else
                row++;
        }

        return false;
    }
}
